#include "stdafx.h"
#include "GlobalSchema.h"
#include "Configure.h"
#include "BSReader.h"
#include "BSWriter.h"
#include <iostream>
#include <fstream>
GlobalSchema* GlobalSchema::globalSchema = NULL;
GlobalSchema::GlobalSchema(void)
{
	initial(); 
}


GlobalSchema::~GlobalSchema(void)
{
    
}
GlobalSchema * GlobalSchema::getInstance(void)
{
    std::cout<<"global schema get instance"<<std::endl;
	if(globalSchema==NULL)
	{
		globalSchema = new GlobalSchema();
	}
	return globalSchema;
}
void GlobalSchema::initial(void)
{
    std::cout<<"global file initialed"<<std::endl;
	std::string schemaFile = Configure::getInstance()->getConfigureValue("schema_file");

	BSReader reader;
	BSValue root;
	std::ifstream is;
	is.open(schemaFile.c_str(),std::ios::binary);
    std::cout<<"one time"<<std::endl;
	if(reader.parse(is,root))
	{
         std::cout<<"one time"<<std::endl;
		int size = root.size();
		for(int i = 0; i< size ; i++)
		{
			BSValue schema = root[i];
           
			std::string schemaTitle = schema["title"].asString();
			this->schemas[schemaTitle] = schema;
		}
	}
}
